package io.renren.modules.app.controller.user.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.exception.RRException;
import io.renren.common.utils.R;
import io.renren.modules.app.dao.YcUserResume;
import io.renren.modules.app.entity.*;
import io.renren.modules.app.entity.index.YcRecruitEntity;
import io.renren.modules.app.entity.index.YcSalaryEntity;
import io.renren.modules.app.service.*;

import io.renren.modules.app.utils.FileUploadUtil;
import org.apache.commons.io.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.*;


/**
 * 
 *
 *
 * @email 928185446qq.com
 * @date 2023-12-20 20:22:55
 */
@RestController
@RequestMapping("userResume")
public class YcUserResumeController {
    //简历
    @Resource
     YcUserResumeService ycUserResumeService;
    //求职意向
    @Resource
     YcUserIntentionJobService ycUserIntentionJobService;
    //职位种类
    @Autowired
     YcPositionTypeService ycPositionTypeService;
    //期望薪资
    @Autowired
     YcSalaryService ycSalaryService;
    //求职状态
    @Autowired
     YcUserJobStatusService ycUserJobStatusService;
    //文件上传工具类
    @Resource
    private FileUploadUtil fileUploadUtil;
    @Autowired
    WorkYearService workYearService;
    @Autowired
    private UserService userService;
    //教育经历
    @Resource
    private YcUserEducationService userEducationService;
    //工作经历
    @Resource
    private YcUserExperienceService userExperienceService;


    /**
     * 信息
     * jiangfuhang
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id,@RequestParam Map<String, Object> params) {
        Map<String,Object> resumeMap=new HashMap<>();
        //定义一个QueryWrapper用来储存用户id
        QueryWrapper<YcUserResumeEntity> queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_id",id);
        //储存id获取基本信息
        YcUserResumeEntity UserResume = ycUserResumeService.getOne(queryWrapper);
        System.out.println("========123"+UserResume);
        resumeMap.put("ycUserResumeEntity",UserResume);
        //获取简历id
        int resumeId = UserResume.getId();
        System.out.println(resumeId);
        System.out.println(id);
        //意向职位
        List<YcUserIntentionJobEntity> UserIntentionJobList =ycUserIntentionJobService.getIntentionJob(id);
        System.out.println("======="+params);
        System.out.println("======"+UserIntentionJobList);
        resumeMap.put("ycUserIntentionJobList",UserIntentionJobList);

        // 获取工作经历信息
        YcUserExperienceEntity UserExperience = userExperienceService.getExperienceById(id);
        resumeMap.put("UserExperience", UserExperience);

        // 获取教育经历信息
        YcUserEducationEntity  UserEducation = userEducationService.getOne(new QueryWrapper<YcUserEducationEntity>().eq("resume_id", resumeId));
        resumeMap.put("UserEducation", UserEducation);

        return R.ok(resumeMap);
    }

    /**
     * 新增
     */
    @PostMapping("/save")
    public R save(YcUserResumeEntity userResume, YcUserIntentionJobEntity userIntentionJob,@RequestParam("file") MultipartFile file ) throws IOException {
        try {
        // 保存文件
        String filePath = fileUploadUtil.saveFile(file);
            System.out.println("----------"+filePath);
        // 设置文件路径
        userResume.setResumePortrait(filePath);
        // 设置添加时间
        userResume.setAddtime(new Date());
        // 设置删除状态
        userResume.setDeletestatus(false);
        // 插入个人简历
        ycUserResumeService.save(userResume);
        //设置添加时间
        userIntentionJob.setAddtime(new Date());
        // 插入求职意向
        ycUserIntentionJobService.save(userIntentionJob);
        } catch (IOException e) {
            return R.error("插入用户时出错。");
        }
        return R.ok();
    }

    @PostMapping("/list")
    public R list(){
        Map<String, Object> resultMap = new HashMap<>();

        List<YcPositionTypeEntity> positionTypeEntityList = ycPositionTypeService.selectList();
        resultMap.put("positionTypeList",positionTypeEntityList);

        //薪资列表
        List<YcSalaryEntity> salaryEntityList = ycSalaryService.list();
        resultMap.put("salaryList",salaryEntityList);

        //求职状态
        List<YcUserJobStatusEntity> jobStatusEntityList = ycUserJobStatusService.list();
        resultMap.put("jobStatusList",jobStatusEntityList);

        //工作年限
        List<WorkYearEntity> workYearEntities = workYearService.list();
        resultMap.put("workYearList",workYearEntities);
        return R.ok(resultMap);


    }






}

